package com.admission.web;

import java.util.List;

import org.apache.commons.lang.xwork.StringUtils;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;
import org.springside.modules.utils.web.struts2.Struts2Utils;

import com.admission.model.Attachment;
import com.admission.service.AttachmentManager;
import com.admission.util.PageUtils;

@Namespace("/base")
@Results({@Result(name = CrudActionSupport.RELOAD, location = "/base/index.action", type = "redirect") })
public class AttachmentAction extends CrudActionSupport<Attachment>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String id;
	private AttachmentManager attachmentManager;
	private Attachment entity;
	private Page<Attachment> page=new Page<Attachment>(PageUtils.DEFAULT_PAGE_SIZE);
	private List<Attachment> attachmentList;
	private String keywords="";
	
	public Attachment getModel() {
		return entity;
	}

	@Override
	public String list() throws Exception {
		List<PropertyFilter> filters=PropertyFilter.buildFromHttpRequest(Struts2Utils.getRequest());
		if(!StringUtils.isEmpty(keywords))
		{
		PropertyFilter p=new PropertyFilter("LIKES_name",keywords);
		filters.add(p);
		}
		page.setOrder(Page.DESC);
		page.setOrderBy("inputTime");
		page=attachmentManager.getByFilter(page, filters);
		attachmentList=page.getResult();
		return SUCCESS;
	}

	@Override
	public String input() throws Exception {
		return RELOAD;
	}
   	 
	@Override
	public String save() throws Exception {
		return RELOAD;
	}

	@Override
	public String delete() throws Exception {
		return RELOAD;
	}

	@Override
	protected void prepareModel() throws Exception {
		if(StringUtils.isEmpty(id))
			entity=new Attachment();
		else
			entity=attachmentManager.getAttachmentById(id);
		
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	

	public Attachment getEntity() {
		return entity;
	}

	public void setEntity(Attachment entity) {
		this.entity = entity;
	}

	public Page<Attachment> getPage() {
		return page;
	}

	public void setPage(Page<Attachment> page) {
		this.page = page;
	}

	public List<Attachment> getAttachmentList() {
		return attachmentList;
	}

	public void setAttachmentList(List<Attachment> attachmentList) {
		this.attachmentList = attachmentList;
	}

	public AttachmentManager getAttachmentManager() {
		return attachmentManager;
	}
	@Autowired
	public void setAttachmentManager(AttachmentManager attachmentManager) {
		this.attachmentManager = attachmentManager;
	}

	public String getKeywords() {
		return keywords;
	}

	public void setKeywords(String keywords) {
		this.keywords = keywords;
	}


}
	